home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b116.asm < prev    next >
Assembly Source File  |  1992-04-28  |  6KB  |  155 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.16    LMS ADAPTIVE FILTER  
  8. ;l      
  9. ;Notation and symbols: 
  10. ;;  x(n)  - Input sample at time n. 
  11. ;  d(n)  - Desired signal at time n. 
  12. ;  f(n)  - FIR filter output at time n. 
  13. ;  H(n)  - Filter coefficient vector at time n.    H={h0,h1,h2,h3} 
  14. ;  X(n)  - Filter state variable vector at time n. X={x0,x1,x2,x3} 
  15. ;  u     - Adaptation gain. 
  16. ;  ntaps - Number of coefficient taps in the filter. For this 
  17. ;          example, ntaps=4. 
  18. ; Exact LMS Algorithm: 
  19. ; e(n)=d(n)-H(n)X(n)    (FIR filter and error) 
  20. ; H(n+1)=H(n)+uX(n)e(n) (Coefficient update) 
  21. ; Delayed LMS Algorithm: 
  22. ; e(n)=d(n)-H(n)X(n)        (FIR filter and error) 
  23. ; H(n+1)=H(n)+uX(n-1)e(n-1) (Coefficient update) 
  24.  
  25. ;In the exact LMS algorithm, the output of the FIR filter is first  calculated (f(n)) and then the coeffi-
  26. ;cients are updated using the  current error signal and coefficients.  In the delayed LMS algorithm,  
  27. ;the FIR filter and coefficient update is performed at the same time. The  coefficients are updated with 
  28. ;the error value and coefficients from the  previous sample.  
  29. ;References: 
  30. ;  "Adaptive Digital Filters and Signal Analysis", Maurice G. Bellanger 
  31. ;      Marcel Dekker, Inc. New York and Basel 
  32. ;  "The DLMS Algorithm Suitable for the Pipelined Realization of Adaptive 
  33. ;      Filters", Proc. IEEE ASSP Workshop, Academia Sinica, Beijing, 1986 
  34. ;
  35. ;The sections of code shown describe how to initialize all registers,  filter an input sample and do the 
  36. ;coefficient update.  Only the  instructions relating to the filtering and coefficient update are shown  as 
  37. ;part of the benchmark.  Instructions executed only once (for  initialization) or instructions that may 
  38. ;be user application dependent  are not included in the benchmark.  
  39. ;                                                    Exact LMS Algorithm 
  40. ntaps    equ     4 
  41. u        equ     .01 
  42.  
  43.          org     x:0 
  44. sbuf     ds      ntaps 
  45.  
  46.          org     y:0 
  47. cbuf     ds      ntaps 
  48.  
  49.          org     y:10 
  50. dsig     ds      1 
  51. xsig     ds      1 
  52.  
  53.          org     p:$50 
  54. start 
  55.   move      #sbuf,r0            ;point to state buffer 
  56.   move      #cbuf,r4            ;point to coefficient buffer 
  57.   move      r4,r5               ;extra pointer 
  58.   move      #ntaps-1,m0         ;mod on pointers 
  59.   move      #ntaps-1,m4 
  60.   move      #ntaps-1,m5 
  61.   move      #-3,n0              ;final adjustment 
  62.   move      #u,d7.s             ;adaptation constant 
  63.  
  64. main 
  65.   fclr    d1                            y:xsig,d4.s 
  66.   fclr    d0            d4.s,x:(r0)+    y:(r4)+,d5.s 
  67.   rep     #ntaps 
  68.   fmpy    d4,d5,d1  fadd.s d1,d0  x:(r0)+,d4.s  y:(r4)+,d5.s 
  69.   fadd.s  d1,d0         x:(r0)-,d4.s    y:(r4)-,d5.s 
  70.  
  71.   move                                  y:dsig,d1.s 
  72.   fsub.s  d0,d1 
  73.   fmpy.s  d7,d1,d1      x:(r0)+,d4.s 
  74.  
  75.   fmpy.s  d4,d1,d3                      y:(r4)+,d5.s 
  76.   fadd.s  d3,d5         x:(r0)+,d4.s 
  77.   do      #ntaps,cup 
  78.   fmpy.s  d4,d1,d3      d5.s,d0.s       y:(r4)+,d5.s 
  79.   fadd.s  d3,d5         x:(r0)+,d4.s    d0.s,y:(r5)+ 
  80. cup 
  81.   move                  x:(r0)+n0,d4.s  y:(r4)-,d0.s 
  82.   jmp     main 
  83.   end 
  84.  
  85. ;The FIR filter requires 1N/coefficient and the coefficient update  requires 2N/coefficient for a total of 
  86. ;3N/coefficient.  
  87. ;On the delayed LMS algorithm, the coefficients are updated with the  error from the previous itera-
  88. ;tion while the FIR filter is being computed  for the current iteration.  In the following implementation, 
  89. ;two  coefficients are updated with each pass of the loop.  
  90. ;                                            Delayed LMS Algorithm 
  91.  
  92. iter      equ   50              ;Number of LMS iterations 
  93. conv_fact equ   0.01            ;Convergence factor 
  94.  
  95.           org   x:$0 
  96. state     ds    11              ;State of lms fir 
  97.  
  98.           org   y:$0 
  99. coef      ds    10              ;LMS coefficients 
  100.  
  101. e         dc    0.0             ;Signal error 
  102. xin       ds    1               ;Input to system 
  103. dsig      ds    1               ;Desired signal 
  104.  
  105.           org   p:$100 
  106. lmstest 
  107.   move   #state,r0          ;Set up address generators 
  108.   move   #10,m0 
  109.   move   #xstate,r1 
  110.   move   #9,m1 
  111.   move   #coef,r4 
  112.   move   #9,m4 
  113.   move   #coef,r5 
  114.   move   #9,m5 
  115.   move   #xcoef,r6 
  116.   move   #9,m6 
  117.  
  118.   move   #iter,d0.l 
  119.   do     d0.l,lms 
  120.   ; LMS algorithm setup 
  121.   move                                         y:e,d0.s 
  122.   move                           #conv_fact,d1.s 
  123.   fmpy.s d0,d1,d0                              y:xin,d6.s 
  124.   move                           d0.s,d9.s 
  125.   move                           d6.s,x:(r0) 
  126.   ; LMS algorithm loop 
  127.   move                           x:(r0)+,d6.s  y:(r4)+,d7.s 
  128.   fmpy.s d7,d6,d1                x:(r0)+,d4.s  y:(r4)+,d5.s 
  129.   fmpy.s d9,d4,d2 
  130.   fmpy   d5,d4,d0  fadd.s d7,d2  x:(r0)+,d6.s 
  131.   do #4,_lms_loop 
  132.   fmpy   d9,d6,d3  fadd.s d0,d1                y:(r4)+,d7.s 
  133.   fmpy   d7,d6,d0  fadd.s d5,d3  x:(r0)+,d4.s  d2.s,y:(r5)+ 
  134.   fmpy   d9,d4,d2  fadd.s d0,d1                y:(r4)+,d5.s 
  135.   fmpy   d5,d4,d0  fadd.s d7,d2  x:(r0)+,d6.s  d3.s,y:(r5)+ 
  136. _lms_loop 
  137.  
  138.   fmpy   d9,d6,d3  fadd.s d0,d1                d2.s,y:(r5)+ 
  139.                    fadd.s d5,d3  (r0)- 
  140.   move                                         d3.s,y:(r5)+ 
  141.   move                                         y:dsig,d2.s 
  142.   fsub.s                         d1,d2 
  143.   move                                         d2.s,y:e 
  144. lms 
  145.   nop 
  146.   nop 
  147.   end 
  148.  
  149. ;The inner loop updates the coefficients and performs the FIR filtering  for a speed of 2N per coeffi-
  150. ;cient.  
  151.